<template>
	<view style="background-color: #F7F7F7;">
		<view class="topbg" :style="backStyle"></view>
		<counselorNav :info="info" />
		<banner />
		<store :store="store" :noticeList="noticeList" />
		<service :healthStatus="healthStatus" :service="service" :result="result" @applyService="startHealthService"/>
		<activty title="运营活动" :items="items" @goPage="jumpPages"/>
		<view style="height: 20px;" />

	</view>
</template>

<script>
	// import healthCard from './components/health-card.vue'
	// import community from './components/community.vue'
	// import forum from './components/forum.vue'
	// import consultingService from './components/consultingService.vue'
	// import commodity from './components/commodity.vue'
	import banner from './components/banner.vue'
	import store from './components/store.vue'
	import service from './components/service.vue'
	import counselorNav from './components/counselorNav.vue'
	import activty from './components/activty.vue'
	
	export default {
		components: {
			counselorNav,
			banner,
			store,
			service,
			activty

		},
		data() {
			return {
				noticeList: [],
				info: undefined,
				service: undefined,
				navHeight: global.navHeight, //导航栏高度
				store: undefined,
				backStyle: '',
				items: [
					{ title: '健康任务', icon: 'https://pics.leshiguang.com/vpage/2024/01/19/b0951f17e5ac49a69211be54331a88b4.png', page: '/pagesHome/health-assessment/health-task'},
					{ title: '分享有礼', icon: 'https://pics.leshiguang.com/vpage/2024/01/19/c8398fdf74a4458386bcc2c36e9d7da6.png', page: '/pagesHome/share-politely/share-politely'},
				],
				contFlag: false,
				isFollow: false,
				publicNoFlag: false, //是否关注公众号
				list: [{
						name: '健康资讯',
						id: 'consultingService'
					}, {
						name: '健康讲堂',
						id: 'forum'
					}, {
						name: '推荐商品',
						id: 'commodity'
					},
					{
						name: '圈子',
						id: 'community'
					}
				],
				current: 0,
				currentId: 'consultingService',
				informationNum: 0, //消息数
				healthStatus: [], //健康状态列表

				patternIndex: 0, //中医和西医报告切换
				result: '', //健康报告
				send: false, //是否有事件在点击中
				openNavbar: false, //是否点击头像 展开导航
				userData: global.userInfo,
				isLogin: false, //默认没有登录
				carList: [{
						page: '/pagesHome/health-assessment/health-task',
						url: 'http://static.bsyjk.cn/shoppingMall/BB04CB7974934EDF89116BBEA9BF906A.png',
						name: '健康任务',
						enText: 'Health task',
						color: '#56716F'
					},
					{
						page: '/pagesHome/share-politely/share-politely',
						url: 'http://static.bsyjk.cn/shoppingMall/B33ACE13D51240849EFE3E10D0021723.png',
						name: '分享有礼',
						enText: 'Share politely',
						color: '#B59F8F'
					},
					{
						page: '/pagesMy/my/family/family',
						url: 'http://static.bsyjk.cn/shoppingMall/F91AF0BEA8B24B0DA7D34087D0575608.png',
						name: '家人互联',
						enText: 'Family interconnection',
						color: '#5AC5F8'
					},
					{
						page: '/subpackage/bodyFatScale/bodyFatScale',
						url: 'http://static.bsyjk.cn/shoppingMall/709BFC19B4C34B418175DA2BB4746232.png',
						name: '人体成分分析',
						enText: 'composition analysis',
						color: '#595A52'
					}
				],
				navBarList: [{
						page: '/pagesMy/health-records/health-records',
						url: 'shoppingMall/A351F710D2004DF18424267C1F006BBE.png',
						num: 0,
						name: '健康档案'
					},
					{
						page: '/pagesMy/health-records/my-report',
						url: 'shoppingMall/435346B5CECC479289D0D63549868182.png',
						num: 0,
						name: '我的报告'
					},
					{
						page: '/pages/subpackage/SignIn/SignIn',
						url: 'shoppingMall/C51532EFBF5C47F0A9E54AC897F7D2F0.png',
						num: 0,
						name: '我的签到'
					},
					{
						page: '/pagesMy/my/news/news',
						url: 'shoppingMall/47D68ABDBC514C1C9A0EC2B94E56896C.png',
						num: 0,
						name: '我的消息'
					},
					{
						page: '/pagesMy/my/counselor/counselor',
						url: 'shoppingMall/5B1CE08DC5124FE59C9C37D9C223F05D.png',
						num: 0,
						name: '我的顾问'
					}
				],
				familyList: [], //家人列表

				enterTheScene: '', //微信小程序进入场景

				
			}
		},
		onLoad(e) {
			// 设置背景高度
			uni.getSystemInfo({
					success: (res) => {
					const menu = uni.getMenuButtonBoundingClientRect();
					this.navHeight = (menu.bottom + menu.top - res.statusBarHeight);
					this.backStyle = `top: ${this.navHeight}px;`;
				}});
			
			if (e.type == 1) { //门店端跳转
				this.$urouter.navigateTo({
					url: '/pagesMy/my/relevance/relevance',
					params: {
						code: e.code,
						name: e.name,
						imgUrl: e.imgUrl
					}
				});
			} else if (e.type == 2) { //顾问分享 邀请绑定
				this.$urouter.navigateTo({
					url: '/pagesMy/my/relevance/share',
					params: {
						code: e.code,
						name: e.name,
						imgUrl: e.imgUrl
					}
				});
			} else if (e.type == 3) { //分享文章
				this.$urouter.navigateTo({
					url: '/pages/subpackage/find/articleDetails/details',
					params: {
						id: e.id
					}
				});
			} else if (e.type == 4) { //视频
				this.$urouter.navigateTo({
					url: '/pages/subpackage/find/video-detail/video-detail',
					params: {
						id: e.id
					}
				});
			} else if (e.type == 5) { //我的添加家人
				this.userSwc({
					relationName: '添加'
				}, 0)
			} else if (e.type == 6) { //2+1他人报告
				this.$urouter.navigateTo({
					url: '/pages/subpackage/home/HealthReport/HealthReport',
					params: {
						phone: e.phone,
						userAnsId: e.userAnsId,
						nickName: e.nickName,
						avatarUrl: e.avatarUrl
					}
				});
			} else if (e.type == 7) { //中医他人报告
				this.$urouter.navigateTo({
					url: '/subpackage/TCM-Report/TCM-Report',
					params: {
						phone: e.phone,
						userAnsId: e.userAnsId,
						nickName: e.nickName,
						avatarUrl: e.avatarUrl
					}
				});
			}

			wx.showShareMenu({
				withShareTicket: true,
				//设置下方的Menus菜单，才能够让发送给朋友与分享到朋友圈两个按钮可以点击
				menus: ["shareAppMessage", "shareTimeline"]
			})
		},
		onLaunch(options) {
			let option = JSON.stringify(options);
			console.log('app.js option-----onLaunchonLaunchonLaunchonLaunchonLaunch啦啦啦啦啦啦啦啦' + option)
		},
		onShow(options) {
			if (global.token) {
				this.userData = global.userInfo;
				this.isLogin = true;
				this.userAnswer(); //健康水平
				this.getMessage(); //消息数
				// this.getFamilyList(); //获取家人列表
				this.getHealthService(); // 获取服务状态
				this.getMyStore(); // 获取门店
				this.getAdviserList(); // 获取顾问信息
			} else {
				this.isLogin = false;
			}
			// this.$refs.healthCard.getCurve(); //更新首页的卡片数据
			this.getHealthStatus();
			this.followPublicNo(); //获取用户是否关注公众号
			let getLaunchOptionsSync = uni.getLaunchOptionsSync();
			this.enterTheScene = getLaunchOptionsSync.scene;
			console.log(getLaunchOptionsSync, '进入场景')
		},
		//上拉加载
		onReachBottom: function() { //分页加载
			// this.$refs[this.currentId].pullUpLoading();

		},
		//下拉刷新
		onPullDownRefresh() {
			// this.$refs.healthCard.getCurve();
			this.followPublicNo(); //获取是否关注公众号
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		//方法
		methods: {
            //获取用户头像
            getAvatarUrl(avatarUrl){
                if(avatarUrl==null || (avatarUrl.indexOf("qlogo") !=-1 && avatarUrl.indexOf("9VemZoJ8rg") != -1) ){
                    return global.DEFAULT_AVATARURL
                }
                return avatarUrl;
            },
			//去登录
			goToLogin() {
				this.$basejs.globaltoken();
			},
			//是否展示关注公众号
			followPublicNo() {
				this.$loginl.get(global.apiUrls.followPublicNoUrl).then(res => {
					if (res.data.code == 6000) {
						this.contFlag = true;
					} else {
						this.contFlag = false;
						this.publicNoFlag = !res.data.success;
						console.log(res.data.success, '------------------00000000000----------------')
					}
				})
			},
			//获取家人列表
			getFamilyList() {
				this.familyList = [];
				this.$https.get(global.apiUrls.getFamilyList(global.userInfo.userId)).then(res => {
					if (res.data.code === 1000) {
						this.familyList = res.data.result;
					}
				})
			},
			getAdviserList() {
				let _this = this;
				this.$loginl.get(global.apiUrls.getAdviserList + '?userId=' + uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z')
						.userId, {})
				.then(res => {
					if (res.data.code == 1000) {
						_this.info = res.data.result;
					}
				})
    	},
			jumpPages(val) {
				//如果是家人互联，需判断有没有家人
				if (val.name === '家人互联') {
					if (this.familyList.length === 0 || !this.familyList) {
						this.$urouter.navigateTo('/pagesHome/family-connectivity/family-connectivity');
					} else {
						this.$urouter.navigateTo({
							url: '/pagesHome/family-connectivity/family-internet-list',
							params: {
								anotherUserId: this.familyList[0].anotherUserId,
								index: 0
							}
						});
					}
				} else {
					this.$urouter.navigateTo(val.page);
				}
				this.openNavbar = false;
			},
			fengxbaog(starNum) {
				this.$basejs.globaltoken();
				let patternIndex = this.patternIndex;
				if (patternIndex == 0) { //2+1评测
					if (starNum) {
						uni.navigateTo({
							url: '/pages/subpackage/home/HealthReport/HealthReport?userAnsId=' + uni
								.getStorageSync(
									'userAnsId')
						})
					} else {
						uni.navigateTo({
							url: '/pages/subpackage/home/oneAccess/evaluating'
						})
					}
				} else if (patternIndex == 1) { //中医评测
					if (starNum) {
						uni.navigateTo({
							url: '/subpackage/TCM-Report/TCM-Report?userAnsId=' + uni.getStorageSync(
								'userAnsId') + '&topicId=4'
						})
					} else { //没测评去测评
						uni.navigateTo({
							url: '/subpackage/TCM-evaluation/TCM-evaluation?topicId=4'
						})
					}
				}

			},
			//获取健康状态
			getHealthStatus() {
				let parameter = {}
				if (this.isLogin) parameter['hisUserId'] = global.userInfo.userId
				this.$https.get(global.apiUrls.getHealthStatus, parameter).then(res => {
					this.healthStatus = res.data.result;
				})
			},

			// 获取消息条数
			getMessage() {
				let _this = this;
				this.$https.get(global.apiUrls.getMessage,{sourceType:1})
					.then(res => {
						if (res.data.code == 1000) {
							let result = res.data.result;
							_this.informationNum = result.comment += result.fans += result.like += result.system; //总数
							this.navBarList[3].num = _this.informationNum;
						}
					})
			},

			//切换导航栏
			change(e) {
				this.current = e;
				this.currentId = this.list[e].id;
			},
			//获取健康水平
			userAnswer() {
				let _this = this;
				let topicId = 3,
					starNum; //星
				this.$api.get(global.apiUrls.userAnswer + '/' + global.userInfo.userId + '/' + topicId, {})
					.then(res => {
						if (res.data.code == 1000) {
							let result = res.data.result;
							if (result.healthLevel == 'A') {
								starNum = 5
							} else if (result.healthLevel == "B") {
								starNum = 4
							} else if (result.healthLevel == "C") {
								starNum = 3
							} else if (result.healthLevel == "D") {
								starNum = 2
							} else if (result.healthLevel == "E") {
								starNum = 1
							}
							result.starNum = starNum;
							let updateTime = _this.$basejs.dataType(result.updateTime);
							result.updateTime = updateTime.n + '.' + updateTime.y + '.' + updateTime.r;
							_this.result = result; //健康报告
							if (result.userAnsId) {
								uni.setStorageSync('userAnsId', result.userAnsId)
							}
						}
					}).catch(err => {})
			},

			//点击头像
			openNav() {
				this.openNavbar = !this.openNavbar;
			},
			goCounselor() {
				uni.navigateTo({
						url: '/pagesMy/my/counselor/counselor'
					})
			},
			getHealthService() {
				this.$https.get(global.apiUrls.checkStartHealthService, {
					userId: global.userInfo.userId
				}).then(res => {
					this.service = res.data.result;
				})
    	},
			startHealthService() {
				if (global.token) {
					this.$https.get(global.apiUrls.startHealthService, {
						userId: global.userInfo.userId
					}).then(res => {
						this.service = res.data.result;
					})
					return;
				}
				this.$basejs.globaltoken();
    	},
			getMyStore() {
				this.$https.get(global.apiUrls.myStore, {
					userId: global.userInfo.userId
				}).then(res => {
					this.store = res.data.result;
					global.store = this.store
					this.getNotice()
				})
			},
			onBannerClick(item, idx) {

			},
			getNotice() {
				this.$https.get(global.apiUrls.noticeList, {
					userId: global.userInfo.userId,
					storeId: this.store.storeId
				}).then(res => {
					this.noticeList = res.data.result;
				})
			}
		}
	}
</script>

<style lang="scss">
	.head-portrait {
		position: relative;
		display: flex;
		align-items: center;

		.head-desc {
			font-size: 16px;
			font-weight: bold;
		}

		.head-image {
			width: 32px;
			height: 32px;
			margin-right: 4px;
		}
		.suspension-bar {
			top: 100rpx;
			position: absolute;
			height: 410rpx;
			width: 356rpx;
			border-radius: 10rpx;
			background-color: #fff;
			box-shadow: 0rpx 2rpx 20rpx 0rpx rgba(173, 173, 173, 0.25);
			padding: 0rpx 20rpx;

			.every-bar {
				display: flex;
				align-items: center;
				padding: 20rpx;
				border-bottom: 1rpx solid #DDDDDD;

				.navbar-name {
					font-size: 30rpx;
					font-weight: 400;
					color: #000000;
					margin-left: 24rpx;
				}
			}
		}

		.triangle {
			position: absolute;
			top: 80rpx;
			left: 10rpx;
			width: 0;
			height: 0;
			border-left: 30rpx solid transparent;
			border-right: 30rpx solid transparent;
			border-bottom: 50rpx solid #fff;
			// box-shadow: 0rpx 2rpx 20rpx 0rpx rgba(173, 173, 173, 0.25);
		}
	}

	.topbg {
		top: 0;
		width: 750upx;
		height: 280upx;
		background: linear-gradient(0deg, #AFD1D900 0%, #AFD1D9 100%);
		background-size: 750upx 280upx;
		box-sizing: border-box;
		position: absolute;
	}

	

	.contt {
		position: fixed;
		bottom: 0;
	}

	.cont {
		// background-color: #666666;
		background: rgba(0, 0, 0, 0.7);
		opacity: 0.8;
		color: #ffffff;
		position: fixed;
		bottom: 0;
		width: 750rpx;
		height: 58rpx;
		display: flex;
		align-items: center;
		padding: 0 24rpx;
		justify-content: space-between;

		.cont1 {
			font-size: 24rpx;
		}

		.cont2 {
			padding: 8rpx 30rpx;
			background-color: #2EA7E0;
			border-radius: 20rpx;
			font-size: 20rpx;

		}
	}

	//内容盒子
	.content-box {
		padding: 28rpx 24rpx;
		background-color: #ffffff;

		//健康水平
		.jump-details-box {
			padding: 0 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			background-image: url('http://static.bsyjk.cn/topbg/D41800DF6F434DE7B1D1FFCB21CF3EF3.png');
			background-size: 100% 100%;
			height: 175rpx;
			box-shadow: 0rpx 2rpx 20rpx 0rpx rgba(173, 173, 173, 0.25);
			border-radius: 40rpx 40rpx 0rpx 0rpx;
		}

		.fraction {
			width: 144rpx;
			height: 144rpx;
			background-image: url('http://static.bsyjk.cn/Group2x/EB5AB2CBF6F44A9B8C153366402D2CAA.png');
			background-size: 100% 100%;
			font-size: 30rpx;
			font-weight: 600rpx;
			text-align: center;
			line-height: 144rpx;
			color: #F5A623;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			.scoreText {
				font-size: 40rpx;
				line-height: 40rpx;
				margin-top: -10rpx;
			}


		}

		.level-of-health {
			width: 320rpx;
			color: #81C042;

			.horizontal-title {
				font-size: 36rpx;
				font-weight: 500;
			}

			.horizontal-results {
				font-size: 24rpx;
			}
		}
	}

	//健康进度
	.health-testing {
		margin-top: 60rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #fff;
		padding: 10rpx 24rpx;

		.each-progress {

			.progress-name {
				width: 80rpx;
				height: 80rpx;
				font-size: 20rpx;
				padding: 16rpx 18rpx;
				border-radius: 15rpx;
				background: #D7EEF9;
				color: #2EA7E0;
				text-align: center;
			}

			.arrow-icon {
				margin-left: 6rpx;
			}
		}

		.each-progress-n {

			.progress-name {
				width: 80rpx;
				height: 80rpx;
				font-size: 20rpx;
				padding: 16rpx 18rpx;
				border-radius: 15rpx;
				background: #ECECEC;
				color: #9B9B9B;
				text-align: center;
			}

			.arrow-icon {
				margin-left: 6rpx;
			}
		}


	}

	.task-card {
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex-wrap: wrap;
		padding: 22rpx;

		.every-card {
			width: 344rpx;
			height: 100rpx;
			background-size: 100% 100%;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			padding: 16rpx 22rpx;
			margin-top: 30rpx;
		}

		.big-name {
			font-size: 30rpx;
			font-weight: 500;
		}

		.small-name {
			font-size: 20rpx;
			font-weight: 400;
		}
	}
</style>
